/*******************************************************************************
 *
 *    Copyright (c) Baina Info Tech Co. Ltd
 *
 *    Hero_Sexual Life
 *    
 *    Settings
 *    TODO File description or class description.
 *
 *    @author: zuochen
 *    @since:  2010-10-11
 *    @version: 1.0
 *
 ******************************************************************************/

package small.hero.sexual.life.tips.zl;

import com.google.ads.AdRequest;
import com.google.ads.AdSize;
import com.google.ads.AdView;

import small.hero.perprecemanager.SharePreferenceManager;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.LinearLayout;

/**
 * Settings of Hero_Sexual Life.
 * 
 * @author zuochen
 * 
 */

public class Settings extends Activity {
	SharePreferenceManager mSharePreferenceManager;
	private LinearLayout linearLayoutTextSize;
	private LinearLayout linearLayoutTextColor;
	private LinearLayout linearLayoutBackgroundBackground;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.setting);
		bundleView();
		initData();
		
		//广告
		final LinearLayout layout = (LinearLayout) findViewById(R.id.linearLayout);
		final AdView adView = new AdView(this, AdSize.BANNER, "a14e3bcb363a67c");
		layout.addView(adView);
		adView.loadAd(new AdRequest());
	}

	private void bundleView() {
		linearLayoutTextSize = (LinearLayout) findViewById(R.id.LinearLayout01);
		linearLayoutTextColor = (LinearLayout) findViewById(R.id.LinearLayout02);
		linearLayoutBackgroundBackground = (LinearLayout) findViewById(R.id.linearLayout3);
	}

	private void initData() {
		mSharePreferenceManager = new SharePreferenceManager(this);
		linearLayoutTextSize.setOnClickListener(mClickListener);
		linearLayoutTextColor.setOnClickListener(mClickListener);
		linearLayoutBackgroundBackground.setOnClickListener(mClickListener);
	}

	private final OnClickListener mClickListener = new OnClickListener() {

		@Override
		public void onClick(View v) {
			switch (v.getId()) {
			case R.id.LinearLayout01:
				setContentTextSize();
				break;
			case R.id.LinearLayout02:
				setContentTextColor();
				break;
			case R.id.linearLayout3:
				setBackgroundColor();
				break;
			}
		}
	};

	private void setContentTextSize() {
		int whichChoosed = mSharePreferenceManager.getTextSizeSetting();
		new AlertDialog.Builder(Settings.this).setTitle(R.string.size_setting)
				.setSingleChoiceItems(R.array.text_size, whichChoosed,
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
								mSharePreferenceManager
										.setTextSizeSetting(whichButton);
								dialog.dismiss();
							}
						}).setPositiveButton("Cancel",
						new DialogInterface.OnClickListener() {
							public void onClick(DialogInterface dialog,
									int whichButton) {
							}
						}).show();
	}

	private void setContentTextColor() {
		int whichChoosed = mSharePreferenceManager.getTextColorSetting();
		new AlertDialog.Builder(Settings.this).setTitle(
				R.string.text_color_setting).setSingleChoiceItems(
				R.array.text_color, whichChoosed,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						mSharePreferenceManager
								.setTextColorSetting(whichButton);
						dialog.dismiss();
					}
				}).setPositiveButton("Cancel",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
					}
				}).show();
	}

	private void setBackgroundColor() {
		int whichChoosed = mSharePreferenceManager.getTextBackgroundSetting();
		new AlertDialog.Builder(Settings.this).setTitle(
				R.string.background_color_setting).setSingleChoiceItems(
				R.array.text_color, whichChoosed,
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
						mSharePreferenceManager
								.setTextBackgroundSetting(whichButton);
						dialog.dismiss();
					}
				}).setPositiveButton("Cancel",
				new DialogInterface.OnClickListener() {
					public void onClick(DialogInterface dialog, int whichButton) {
					}
				}).show();
	}

	@Override
	protected void onDestroy() {
		setResult(RESULT_OK);
		super.onDestroy();
	}

}
